package crons

import (
	"context"
	"go.didapinche.com/foundation/plat-echo/app/ops/services"
	"go.uber.org/zap"
)

type HostJob struct {
	logger      *zap.Logger
	hostService services.HostService
}

func NewHostJob(logger *zap.Logger,
	hostService services.HostService,
) *HostJob {
	job := &HostJob{
		logger:      logger.With(zap.String("type", "crons.HostJob")),
		hostService: hostService,
	}
	return job
}

func (s *HostJob) Run() {
	s.logger.Info("sync host resources cron start")
	ctx := context.Background()
	err := s.hostService.SyncHostResource(ctx)
	if err != nil {
		s.logger.Error("call SyncHostResource() error: " + err.Error())
	}
	s.logger.Info("sync host resources cron end")
}

func (s *HostJob) Init() {
	s.Run()
}

func (s *HostJob) Cron() string {
	return "0 0 9 * * ?"
}

func (s *HostJob) Name() string {
	return "host_job"
}
